/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ar.lucas.controlgasto.conexion;

import java.sql.Connection;
import java.sql.DriverManager;
/**
 *
 * @author lucmussi
 */
public class MyConnection {
    private static Connection con = null;


    public static Connection getConnection(){
        try {
            if (con == null){
                Runtime.getRuntime().addShutdownHook(new MiShDwnHook());
                String driver= "com.mysql.jdbc.Driver";
    //            String url= "jdbc:mysql://localhost/control_gasto";
    //            String pwd= "prueba";
    //            String usr= "root";
//                String url= "jdbc:mysql://corvuspc.dyndns-ip.com/control_gasto";
//                String pwd= "nietolala";
//                String usr= "corvus";
                String url= "jdbc:mysql://190.210.94.193/control_gasto";
                String pwd= "nietolala";
                String usr= "corvus";
                Class.forName(driver);
                con= DriverManager.getConnection(url,usr,pwd);
            }
            return con;
       } catch (Exception ex){
                ex.printStackTrace();
                throw new RuntimeException("Error al crear la conexion", ex);
                }
    }


static class MiShDwnHook extends Thread{
      public void run(){
          try{
              Connection con = MyConnection.getConnection();
          }
          catch (Exception ex){
              ex.printStackTrace();
              throw new RuntimeException(ex);
          }
      }
    }
}
